<template>
  <div class="content">
    <el-page-header :content="`订单号:${this.$route.params.id}`" @back="goBack" />
    <el-descriptions class="detail" title="酒店订单" :column="2" border>
      <el-descriptions-item label="酒店" span="2">{{ hotel.name }}</el-descriptions-item>
      <el-descriptions-item label="房间" span="2">{{ room.name }}</el-descriptions-item>
      <el-descriptions-item label="订单创建时间" span="2">{{ order.creatTime }}</el-descriptions-item>
      <el-descriptions-item v-if="order.type" label="状态">
        <el-tag v-if="order.type.id === 1" type="danger" size="small">{{ order.type.name }}</el-tag>
        <el-tag v-else-if="order.type.id === 2" type="success" size="small">{{ order.type.name }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="消费">{{ order.price }}￥</el-descriptions-item>
      <el-descriptions-item label="入住时间">{{ order.inDate }}</el-descriptions-item>
      <el-descriptions-item label="入住天数">{{ order.days }}天</el-descriptions-item>
    </el-descriptions>

    <el-descriptions v-if="user" class="detail" title="用户详情" :column="3" border>
      <el-descriptions-item label="用户id">{{ user.id }}</el-descriptions-item>
      <el-descriptions-item label="用户名">{{ user.name }}</el-descriptions-item>
      <el-descriptions-item label="电话">{{ user.phone }}</el-descriptions-item>

    </el-descriptions>
    <el-descriptions v-if="hotel" class="detail" title="酒店详情" :column="3" border>
      <template slot="extra">
        <el-button size="small" type="primary" @click="goHotel">查看酒店</el-button>
      </template>
      <el-descriptions-item label="酒店" :span="3">{{ hotel.name }}</el-descriptions-item>
      <el-descriptions-item label="价钱" :span="1">{{ hotel.price }}￥</el-descriptions-item>
      <el-descriptions-item label="主题" :span="2">{{ hotel.hotelTheme.name }}</el-descriptions-item>
      <el-descriptions-item label="介绍" :span="3">
        <span v-html="hotel.introduce" />
      </el-descriptions-item>
      <el-descriptions-item label="地址" :span="3">
        <span v-html="hotel.address" />
      </el-descriptions-item>
      <el-descriptions-item label="推荐理由" :span="3">
        <span v-html="hotel.recommend" />
      </el-descriptions-item>
      <el-descriptions-item label="环境" :span="3">
        <span v-html="hotel.surrounding" />
      </el-descriptions-item>
    </el-descriptions>
    <el-descriptions v-if="room" class="detail" title="房间详情" :column="3" border>
      <el-descriptions-item label="房间" span="3">{{ room.name }}</el-descriptions-item>
      <el-descriptions-item label="床" span="2">{{ room.roomBed.name }}</el-descriptions-item>
      <el-descriptions-item label="价钱" span="1">{{ room.price }}￥</el-descriptions-item>
      <el-descriptions-item label="WIFI">
        <el-tag v-if="room.wifi" type="success">有</el-tag>
        <el-tag v-else type="danger">无</el-tag></el-descriptions-item>
      <el-descriptions-item label="早餐">{{ room.roomBreakfast.name }}</el-descriptions-item>
      <el-descriptions-item label="面积">{{ room.area }}平方米</el-descriptions-item>
      <el-descriptions-item label="楼层">{{ room.floor }}</el-descriptions-item>
    </el-descriptions>
  </div>
</template>

<script>
import { queryHotelOrderById } from '@/api/order'
import { global } from '@/utils/global'
export default {
  data() {
    return {
      tableLoading: false,
      order: {},
      user: {},
      hotel: {
        hotelTheme: {}
      },
      room: {
        roomBed: {},
        roomBreakfast: {}
      }
    }
  },
  created() {
    global.$emit('changeTitle', `订单号:${this.$route.params.id}`)
    this.queryHotelOrderById()
  },
  methods: {
    goBack() {
      this.$router.go(-1)
    },
    goHotel() {
      this.$router.push({ path: `/theme-hotel/room/${this.hotel.id}` })
    },
    queryHotelOrderById() {
      this.tableLoading = true
      queryHotelOrderById(this.$route.params.id).then(res => {
        this.order = res.data
        this.user = this.order.user
        this.hotel = this.order.hotel
        this.room = this.order.room
      }).finally(() => {
        this.tableLoading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.detail{
  margin-top: 24px;
}
</style>
